/*
 * MenueSystem.c
 *
 *  Created on: 20.05.2011
 *      Author: Tavin
 */

#include <stdint.h>

#include "boolean.h"
#include "SystemMenue.h"

#include "icon.h"
#include "IconAcc.h"
#include "IconSpeaker.h"
#include "IconWireless.h"
#include "IconUsb.h"
#include "IconSave.h"

#include "system.h"


#include "buzzer.h"
#include "UI.h"


#define SYSTEM_MENU_COUNT	5
void (* menuFunction [SYSTEM_MENU_COUNT]) ()={SystemMenue_accSwitch
									,SystemMenue_buzzerSwitch
									,SystemMenue_wirelessSwitch
									,SystemMenue_usbSwitch
									,SystemMenue_saveSwitch};




SystemMenue_t systemMenue;



/****************************************************************************************/
/*																						*/
/*	Function : SystemMenue_init								Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.5.21			Status : Working   			*/
/*																						*/
/****************************************************************************************/
void SystemMenue_init()
{
	systemMenue.status.entered=1;
	systemMenue.activeMenue=0;
}





/****************************************************************************************/
/*																						*/
/*	Function : SystemMenue_process							Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.5.22			Status : Working   			*/
/*																						*/
/****************************************************************************************/
void SystemMenue_process()
{

	UIKeys_process();
	//
	if (UI_switchNextMenue()==TRUE)
		{
		systemMenue.activeMenue++;

		if (systemMenue.activeMenue >SYSTEM_MENU_COUNT-1)
			systemMenue.activeMenue=0;

		systemMenue.status.entered=1;
		}



	else if (UI_switchPreviousMenue()==TRUE)
	{
		systemMenue.activeMenue--;

		if (systemMenue.activeMenue <0)
			systemMenue.activeMenue=SYSTEM_MENU_COUNT-1;

		systemMenue.status.entered=1;
		}


	menuFunction[systemMenue.activeMenue] ();
// if flank -> next Menue;
}




/****************************************************************************************/
/*																						*/
/*	Function : SystemMenue_buzzerSwitch						Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.5.22			Status : Working   			*/
/*																						*/
/****************************************************************************************/
void SystemMenue_buzzerSwitch()
{

	if (systemMenue.status.entered==1)
		{
		if (System_isBuzzerOn()==TRUE)
			UI_displayIcon(&iconSpeakerOn);
		else
			UI_displayIcon(&iconSpeakerOff);
		}

	if (UI_switchValueUp()==TRUE)
		{
		UI_displayIcon(&iconSpeakerOn);
		System_buzzerOn();
		}
	else if (UI_switchValueDown()==TRUE)
		{
		UI_displayIcon(&iconSpeakerOff);
		System_buzzerOff();
		}

	systemMenue.status.entered=0;
}



/****************************************************************************************/
/*																						*/
/*	Function : SystemMenue_accSwitch						Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.5.22			Status : Working   			*/
/*																						*/
/****************************************************************************************/
void SystemMenue_accSwitch()
{
	if (systemMenue.status.entered==1)
		{
		if (System_isAccOn()==TRUE)
			UI_displayIcon(&iconAccOn);
		else
			UI_displayIcon(&iconAccOff);
		}


	if (UI_switchValueUp()==TRUE)
		{
		UI_displayIcon(&iconAccOn);
		System_accOn();
		}
	else if (UI_switchValueDown()==TRUE)
		{
		UI_displayIcon(&iconAccOff);
		System_accOff();
		}

	systemMenue.status.entered=0;
}

/****************************************************************************************/
/*																						*/
/*	Function : SystemMenue_wirelessSwitch					Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.5.22			Status : Working   			*/
/*																						*/
/****************************************************************************************/
void SystemMenue_wirelessSwitch()
{

	if (systemMenue.status.entered==1)
		{
		if (System_isWirelessOn()==TRUE)
			UI_displayIcon(&iconWirelessOn);
		else
			UI_displayIcon(&iconWirelessOff);
		}


	if (UI_switchValueUp()==TRUE)
		{
		UI_displayIcon(&iconWirelessOn);
		System_wirelessOn();
		}
	else if (UI_switchValueDown()==TRUE)
		{
		UI_displayIcon(&iconWirelessOff);
		System_wirelessOff();
		}

	systemMenue.status.entered=0;
}

/****************************************************************************************/
/*																						*/
/*	Function : SystemMenue_usbSwitch						Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.5.22			Status : Working   			*/
/*																						*/
/****************************************************************************************/
void SystemMenue_usbSwitch()
{

	if (systemMenue.status.entered==1)
		{
		if (System_isUsbOn()==TRUE)
			UI_displayIcon(&iconUsbOn);
		else
			UI_displayIcon(&iconUsbOff);
		}


	if (UI_switchValueUp()==TRUE)
		{
		UI_displayIcon(&iconUsbOn);
		System_usbOn();
		}
	else if (UI_switchValueDown()==TRUE)
		{
		UI_displayIcon(&iconUsbOff);
		System_usbOff();
		}

	systemMenue.status.entered=0;
}

/****************************************************************************************/
/*																						*/
/*	Function : SystemMenue_saveSwitch						Author : OG					*/
/*																						*/
/*	Description : 								   										*/
/*																						*/
/*	Version : 1.0					Date :2011.5.22			Status : Working   			*/
/*																						*/
/****************************************************************************************/
void SystemMenue_saveSwitch()
{
	UI_displayIcon(&iconSaveOn);

	if (UI_switchValueUp()==TRUE)
		{
		System_saveData();
		}
}
